package cn.hxzy.course.mapper;

import cn.hxzy.common.domain.Courseware;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author niuyi
 * @since 2024-06-22
 */
public interface CoursewareMapper extends BaseMapper<Courseware> {


    //课件名称模糊查询
    @Select("SELECT \n" +
            "    c.course_name AS course_name,\n" +
            "    cw.courseware_name AS courseware_name,\n" +
            "    cw.courseware_id AS courseware_id,\n" +
            "    cw.courseware_path AS courseware_path\n" +
            "FROM \n" +
            "    sys_course AS c\n" +
            "JOIN \n" +
            "    sys_chapter AS ch ON c.course_id = ch.course_id\n" +
            "JOIN \n" +
            "    sys_section AS s ON ch.chapter_id = s.chapter_id\n" +
            "JOIN \n" +
            "    sys_courseware AS cw ON s.section_id = cw.section_id\n" +
            "WHERE \n" +
            "    c.course_id = #{courseId} \n" +
            "    AND cw.courseware_name LIKE '%${coursewareName}%'\n" +
            "    AND c.deleted = 0 \n" +
            "    AND ch.deleted = 0")
    List<Courseware> selectCourseware(String coursewareName,Integer courseId);


    //查此课程所有课件
    @Select("SELECT COUNT(0) FROM sys_courseware WHERE section_id IN(\n" +
            "SELECT section_id FROM sys_section WHERE chapter_id IN(\n" +
            "SELECT chapter_id FROM sys_chapter WHERE course_id=#{courseId}))")
    double selectCount(Long courseId);


    //删除课件
    @Delete("DELETE FROM sys_courseware WHERE courseware_id=#{coursewareId}")
    int deleteCourseware(Integer coursewareId);
}
